<html>

<head>
<meta http-equiv="Content-Language" content="en">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Fika</title>
</head>

<body>

<h1>Fika Documentation</h1>
<p>The Fika is a transforming tool which takes a modular 
grammar and converts it to a classic monolithic one. The output can be used by 
parser generator to make a parser of the given modular grammar.</p>

<h2>Usage</h2>
<p><code>fika source_files.mg main_module.start_NT &gt; output.gr</code></p>
<ul>
  <li><code>source_files.mg</code> – list of input 
  files containing the source of the modular grammar. There has to be at least 
  one input file</li>
  <li><code>main_module.start_NT</code> – last 
  argument specifies the initial nonterminal. It is determined by its module and 
  name (separated by a dot)</li>
  <li><code>output.gr</code> – output file for the 
  monolithic grammar</li>
</ul>
<h2>Source Files</h2>
<p>A source file has a C-like format. All white spaces (space, tab, new line) 
and comments (/* ... */) are ignored by the parser. Identifiers are case 
sensitive. There are reserved keywords: &quot;<code>abstract</code>&quot;, &quot;<code>as</code>&quot;, 
&quot;<code>drop</code>&quot;, &quot;<code>import</code>&quot;, &quot;<code>module</code>&quot;, &quot;<code>override</code>&quot;, 
&quot;<code>rename</code>&quot; and operators: &quot;<code>=&gt;</code>&quot;, &quot;<code>-&gt;</code>&quot;, &quot;<code>|</code>&quot;, 
&quot;<code>;</code>&quot;, &quot;<code>{</code>&quot;, &quot;<code>}</code>&quot;.</p>
<p>Syntax:<code> <b>module</b> <i>module_name</i> <b>{</b> <i>statement</i>; <i>
statement</i>; <i>...</i> <b>}</b></code></p>
<p>One source file may contain any number of modules (0..N). Each module 
consists of any number of statements terminated by a semicolon (<code>;</code>).</p>
<h2>Statements</h2>
<h3>Abstract</h3>
<p>Syntax:<code> <b>abstract</b> <i>nonterminal_name</i>;</code></p>
<p>This statement defines an abstract nonterminal without specifying a rule for 
it. It can be used in the module (or any module imported to) as any normal 
nonterminal however it must be defined later in some module imported to. It 
provides a way to create universal modules and ensures that the nonterminal is 
defined in a other (more specific) module (causes an error if not).</p>
<h3>Import</h3>
<p>Syntax:<br>
<code><b>import</b> <i>module_name</i>;<br>
<b>import</b> <i>module_name</i> <b>rename</b> <i>old_NT_name</i> <b>as</b> <i>
new_NT_name</i>;<br>
<b>import</b> <i>module_name</i> <b>drop</b> <i>NT_to_drop</i>;<br>
/* There may any number of rename or drop options in one statement (separated 
just by a white space): */<br>
<b>import</b> module_name <b>rename</b> A <b>as</b> A2 <b>rename</b> B <b>as</b> 
B2 <b>drop</b> X <b>rename</b> C <b>as</b> C1 <b>drop</b> Y;</code></p>
<p>Import allows to use rules from one module in an another module. It works 
similar to the include command of the C preprocessor but it supports to control 
what is imported:</p>
<ul>
  <li>rename – imports a nonterminal from the source module with a different 
  name. The target name must not have been used both in source and target module 
  yet.</li>
  <li>drop – imports a nonterminal from the source module as abstract to ensure 
  that it will be redefined. It causes no name conflict if this name has been 
  already used in target module.</li>
</ul>
<p>The options are processed from left to right and an option may refer to the 
target name of a previous option. You should avoid that and refer only to the 
source names. If you need to drop and rename the same source nonterminal, use 
the drop option first and then the rename option. All the imported rules are visible to the target module (are public).</p>
<p>A module can be imported only once. A second import of an already imported 
module causes an error.</p>
<h3>Override</h3>
<p>Syntax:<code> <b>override</b> <i>rule_definition</i>;</code></p>
<p>The override keyword tells that the following rule changes the definition of 
an existing nonterminal (or defines an abstract nonterminal). Redefinition of an 
existing nonterminal (including the imported ones) without override causes an 
error.</p>
<h3>Rule</h3>
<p>Syntax:<br>
<code><i>new_NT_name</i> -&gt; ; /* an empty rule */<br>
<i>new_NT_name</i> -&gt; <i>NT_element</i>; /* nonterminal on the right side of the 
rule */<br>
<i>new_NT_name</i> -&gt; &#39;<i>term value</i>&#39;; /* terminal on the right side */<br>
<i>new_NT_name</i> -&gt; A B &#39;x&#39; C; /* concatenation */<br>
<i>new_NT_name</i> -&gt; A | B | C; /* alternation */<br>
<i>new_NT_name</i> -&gt; A1 A2 A3 | B1 B2 B3; /* both concatenation and alternation 
*/</code></p>
<p>This statement defines a new nonterminal and a rule for it (or it changes an 
existing rule if the override keyword is used). You may use any other 
nonterminal defined in the module (or in the imported modules) or a terminal 
definition on the right side of the rule.</p>
<h2 dir="ltr">Formal Definition of the Syntax</h2>
<p dir="ltr"><code>file ::= module*<br>
module ::= &quot;module&quot; module_name &quot;{&quot; statement* &quot;}&quot;<br>
statement ::= (abstract_statement | import_statement | override_statement | 
rule) &quot;;&quot;<br>
<br>
abstract_statement ::= &quot;abstract&quot; NT_name<br>
<br>
import_statement ::= &quot;import&quot; module_name import_option*<br>
import_option ::= import_rename | import_drop<br>
import_rename ::= &quot;rename&quot; NT_name &quot;as&quot; NT_name<br>
import_drop ::= &quot;drop&quot; NT_name<br>
<br>
override_statement ::= &quot;override&quot; rule<br>
<br>
rule ::= NT_name arrow rule_definition<br>
arrow ::= &quot;=&gt;&quot; | &quot;-&gt;&quot;<br>
rule_definition ::= terminal | nonterminal | pipe<br>
terminal ::= &quot;&#39;&quot; string &quot;&#39;&quot;<br>
nonterminal ::= NT_name<br>
pipe ::= &quot;|&quot;<br>
<br>
module_name ::= identifier<br>
NT_name ::= identifier<br>
identifier ::= [A-Za-z_][A-Za-z0-9_]*&nbsp;&nbsp; /* case sensitive */<br>
string := [^&#39;]*</code></p>

</body>

</html>